package com.powernode.config;



import com.powernode.interceptor.SessionTimeoutInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: ycc
 * @Date: 2023/2/15 12:11
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    SessionTimeoutInterceptor sessionTimeoutInterceptor;

    /**
     * 释放静态资源
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/assets/ckeditor/**").
                addResourceLocations("classpath:/static/assets/ckeditor/").
                setCachePeriod(2592000);
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index").setViewName("index");
        registry.addViewController("/login").setViewName("login");
        registry.addViewController("/admin").setViewName("admin");
        registry.addViewController("/dormitoryAdmin").setViewName("DormitoryAdmin");
        registry.addViewController("/dormitoryAdminAdd").setViewName("DormitoryAdminAdd");
        registry.addViewController("/dormitoryAdminEdit").setViewName("DormitoryAdminEdit");
        registry.addViewController("/isolatedMan").setViewName("IsolatedMan");
        registry.addViewController("/isolatedManAdd").setViewName("IsolatedManAdd");
        registry.addViewController("/isolatedManEdit").setViewName("IsolatedManEdit");
        registry.addViewController("/floorAdmin").setViewName("FloorAdmin");
        registry.addViewController("/floorAdminAdd").setViewName("FloorAdminAdd");
        registry.addViewController("/floorAdminEdit").setViewName("FloorAdminEdit");
        registry.addViewController("/towerAdmin").setViewName("TowerAdmin");
        registry.addViewController("/recentGraph").setViewName("RecentGraph");
        registry.addViewController("/dailyReport").setViewName("DailyReport");
        registry.addViewController("/dailyReportEdit").setViewName("DailyReportEdit");
        registry.addViewController("/towerAdminEdit").setViewName("TowerAdminEdit");
        registry.addViewController("/towerAdminAdd").setViewName("TowerAdminAdd");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(sessionTimeoutInterceptor).addPathPatterns("/**").
                excludePathPatterns("/api/indexcard/*","/","/index","/login","/admin","/static/**");
    }

}
